import pagination from '@/views/pagination'  //分页组件
import openDialogForm from './openDialogForm'
import suppleDialogForm from './suppleDialogForm'
import basicDialogForm from './basicDialogForm'
import salesmanDialogForm from './salesmanDialogForm'
import MessAge from './message'   //企业信息组件
import agentHttp from '@/utils/agentHttp.js'
import router from '@/router'
import {debounce} from '@/utils/index.js'
import {confirm} from '@/utils/confirm'      //二次确认组件
import exportExcel from '@/utils/exportExcel' //导出
export default {
  name: 'vehicleFollow',
  components: {
    openDialogForm,suppleDialogForm,basicDialogForm,pagination,salesmanDialogForm,MessAge
  },
  created() {
  this.seachData(this.searchForm);
  this.getStatusMap();
  },
  data() {
    return {
      //搜索字段
      searchForm: {
        name: "",
        person: "",
        phone: "",
        startDate: "",
        endDate: "",
        source: "",
        enable:"",
        isData:"",
        searchCity:"",
        realname:"",
        category:"",
        realNameAuthStartDate:"",
        realNameAuthEndDate:"",
        authStartDate:'',
        authEndDate:''
      },
      //表格字段
      tableData: [],
      //弹窗状态值
      openDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      suppleDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        dealerInfoId:"",
        id:""
      },
      basicDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      salesmanDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      messageVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      formLabelWidth: '120px',
      statusMap:'',
      dealerEnable:'',
      dealerData:'',
      type:'',
      //用于时间选择控制
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
      authEndDateOpt:{
        disabledDate:(time)=>{
          return time.getTime()< new Date(this.searchForm.authStartDate).getTime();
        }
      },
      realNameAuthEndDateOpt:{
        disabledDate:(time)=>{
          return time.getTime()< new Date(this.searchForm.realNameAuthStartDate).getTime();
        }
      },
      resetFormStatus:false
    }
  },
  updata:{

  },
  methods: {
    //查看所有
  seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.postJson('adminApi/admin/dealer/queryAllByTypeCompany?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
              this.tableData = data
        })
      }
    },

    /*搜索按钮方法*/
    //搜索
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //编辑基本资料
    handleBasic(index, row ,bool) {
      row?this.basicDialogFormVisible.id=row.id:this.basicDialogFormVisible.id=""; 
      this.basicDialogFormVisible.isAdd=true;
      this.basicDialogFormVisible.dialogFormVisible=true;
    },
    handleMessage(index, row ,bool){
      row?this.messageVisible.id=row.id:this.messageVisible.id=""; 
      this.messageVisible.isAdd=true;
      this.messageVisible.dialogFormVisible=true;
      
    },
    changeSalesman(index, row ,bool){
      row?this.salesmanDialogFormVisible.id=row.id:this.salesmanDialogFormVisible.id=""; 
      this.salesmanDialogFormVisible.isAdd=true;
      this.salesmanDialogFormVisible.dialogFormVisible=true;
    },
    //编辑开户资料
    handleOpen(index, row, bool) {
      row?this.openDialogFormVisible.id=row.id:this.openDialogFormVisible.id="";
      this.openDialogFormVisible.isAdd=true;
      this.openDialogFormVisible.dialogFormVisible=true;
    },
    //编辑补充资料
    handleSupple(index, row ,bool) {
      row?this.suppleDialogFormVisible.id=row.id:this.suppleDialogFormVisible.id="";
      row?this.suppleDialogFormVisible.dealerInfoId=row.dealerInfoId:this.suppleDialogFormVisible.dealerInfoId="";
      this.suppleDialogFormVisible.isAdd=true;
      this.suppleDialogFormVisible.dialogFormVisible=true;
    },
    handleSee(index, row ,bool) {
      row?this.suppleDialogFormVisible.id=row.id:this.suppleDialogFormVisible.id="";
      row?this.suppleDialogFormVisible.dealerInfoId=row.dealerInfoId:this.suppleDialogFormVisible.dealerInfoId="";
      this.suppleDialogFormVisible.isAdd=false;
      this.suppleDialogFormVisible.dialogFormVisible=true;
    },
    //停用按钮
    handleDisable(index, row) {
      if(!row.enable){
        var message="启用"
      }else{
        var message="停用"
      };
      this.$nextTick(() => {
         confirm(()=>{
           agentHttp.put('adminApi/admin/dealer/disable/'+row.id).then((data)=>{
            if(data.success){  
              //修改启用或者禁用
                this.$message.success(data.data);
                this.seachData({});
                //这里编写数据赋值或者其他逻辑  例如：this.tableData = data;
            } 
          })  
        },()=>{
          this.$message.info("已取消"+message);
        },"确认"+message+"该条数据吗?",message)
      })
     
       
    },
    getStatusMap(){
      agentHttp.get('adminApi/admin/dealer/get_status_map' ).then((data)=>{
        this.statusMap = data.data.dealerSource;
        this.dealerEnable = data.data.dealerEnable;
        this.dealerData = data.data.dealerData;
        this.type=data.data.type;
      })  
    },
    exportExcels(searchForm,url,name){
      exportExcel(searchForm,url,name)
    },
    
  }
}